package com.gxa.meiye.admin.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.meiye.admin.platform.mapper.ShopMapper;
import com.gxa.meiye.admin.platform.pojo.vo.ShopVo;
import com.gxa.meiye.admin.platform.pojo.vo.UpdateShopStatusVo;
import com.gxa.meiye.admin.platform.service.ShopdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ShopdServiceImpl extends ServiceImpl<ShopMapper, ShopVo> implements ShopdService {
    @Autowired
    private ShopMapper shopMapper;

    @Override
    public List<ShopVo> selectShopList() {
        List<ShopVo> shopVos = shopMapper.selectList(null);
        return shopVos;
    }

    @Override
    public void updateStatus(UpdateShopStatusVo shopVo) {
        LambdaUpdateWrapper<ShopVo> shopVoLambdaUpdateWrapper = Wrappers.lambdaUpdate();
        shopVoLambdaUpdateWrapper.eq(ShopVo::getId,shopVo.getId());
        if(shopVo.getStatus()!=0) {
            shopVoLambdaUpdateWrapper.set(ShopVo::getStatus, 0);
        }else {
            shopVoLambdaUpdateWrapper.set(ShopVo::getStatus, 1);
        }
        shopMapper.update(null,shopVoLambdaUpdateWrapper);
    }

    @Override
    public List<ShopVo> selectShops(String select) {
        LambdaQueryWrapper<ShopVo> shopVoLambdaQueryWrapper = Wrappers.lambdaQuery();
        shopVoLambdaQueryWrapper.like(ShopVo::getId,"%"+select+"%").or().like(ShopVo::getName,"%"+select+"%")
                .or().like(ShopVo::getEmail,"%"+select+"%");
        List<ShopVo> shopVos = shopMapper.selectList(shopVoLambdaQueryWrapper);
        return shopVos;
    }
}
